<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商店商品</title>
    <style>
        .goods-ul {
            list-style: none;
            width: 800px;
            height: 1000px;
            margin: auto;
            border: 1px solid #666;
        }

        .goods-ul li.goods-li {
            float: left;
            width: 240px;
            height: 320px;
            margin: 10px;
            border: 1px solid #999;
        }

        .goods-ul li.goods-li.active {
            border: 1px solid red;
        }

        .goods-name {
            height: 70px;
        }
    </style>
</head>

<body>
    <div>
        <ul class="goods-ul">

        </ul>
    </div>

    <script src="./数据.js"></script>

    <script src="./jq.js"></script>
    <script>

        $(function () {
            var liStr = '';
            // ul元素
            var $goodsUl = $('.goods-ul');
            $.each(goodsList, function (i, item) {
                var id = item.id
                liStr += "<li class='goods-li' sku=" + id + ">" +
                    `<a href=./detail.html?id=${id}><img width='200' src=https:${item.image} /></a>` +

                    "<div class='goods-name'>" + item.name + "</div>" +
                    "<div class='goods-brand'>品牌: " + item.brandName + "</div>" +
                    "</li>"
            })
            $goodsUl.html(liStr);


            $goodsUl.on('mouseenter', '.goods-li', function () {
                $(this).addClass('active');
            })
            $goodsUl.on('mouseleave', '.goods-li', function () {
                $(this).removeClass('active');
            })


            $goodsUl.on('click', '.goods-li', function () {
                var id = $(this).attr('sku');
                location.href = './detail.html?id=' + id;
            })
        })
    </script>
</body>

</html>